//package com.ssd.emq;
//
//import com.google.common.base.Strings;
//import com.ssd.business.MsgHandler;
//import com.ssd.business.MsgHandlerContext;
//import com.ssd.emq.utils.JsonUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.eclipse.paho.client.mqttv3.MqttMessage;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
//@Component
//@Slf4j
//public class MqttServiceImpl implements MqttService{
//    @Autowired
//    private MsgHandlerContext msgHandlerContext;
//
//    /**
//     * mqtt消息处理
//     * @param topic
//     * @param message
//     */
//    @Override
//    public void processMessage(String topic, MqttMessage message) {
//        //1.接收消息并记录日志
//        String msgContent = new String(message.getPayload());
//        log.info("接收到消息:"+msgContent);
//        try {
//            //2.解析消息类型
//            String msgType = JsonUtil.getValueByNodeName("msgType",msgContent);
//            if(Strings.isNullOrEmpty(msgType)) return;
//            //3.获取消息处理器
//            MsgHandler msgHandler = msgHandlerContext.getMsgHandler(msgType);
//            if(msgHandler == null)return;
//            //4.处理消息
//            msgHandler.process(msgContent);
//        } catch (IOException e) {
//            log.error("process msg error,msg is: "+msgContent,e);
//        }
//    }
//}
